package cn.chen.hd.mr;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class TextPair implements WritableComparable<TextPair>{

    private Text first;
    private Text second;

    public TextPair(){
        set(new Text(),new Text());
    }

    public TextPair(String first,String second){
        set(new Text(first),new Text(second));
    }

    public TextPair(Text first,Text second){
        set(first,second);
    }

    public Text getFirst() {
        return first;
    }

    public Text getSecond() {
        return second;
    }

    public void set(Text first, Text second){
        this.first = first;
        this.second = second;
    }

    @Override
    public int compareTo(TextPair o) {
        return 0;
    }

    @Override
    public boolean equals(Object o) {
        if(o instanceof TextPair){
            TextPair tp = (TextPair) o;
            return first.equals(((TextPair) o).first) && second.equals(tp.second);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return first.hashCode() * 163 + second.hashCode();
    }

    @Override
    public void write(DataOutput out) throws IOException {
        first.write(out);
        second.write(out);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        first.readFields(in);
        second.readFields(in);
    }
}
